package com.github.glomadrian.materialanimatedswitch.slice;

import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch;
import com.github.glomadrian.materialanimatedswitch.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbilitySlice extends AbilitySlice {
    private Component mainView;
    private MaterialAnimatedSwitch materialAnimatedSwitch;
    private MaterialAnimatedSwitch materialAnimatedSwitch2;
    private MaterialAnimatedSwitch materialAnimatedSwitch3;
    private MaterialAnimatedSwitch materialAnimatedSwitch4;
    private MaterialAnimatedSwitch masterSwitch;

    private ToastDialog toastDialog;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        mainView = findComponentById(ResourceTable.Id_main);
        materialAnimatedSwitch = (MaterialAnimatedSwitch) findComponentById(ResourceTable.Id_pin);
        materialAnimatedSwitch2 = (MaterialAnimatedSwitch) findComponentById(ResourceTable.Id_pin2);
        materialAnimatedSwitch3 = (MaterialAnimatedSwitch) findComponentById(ResourceTable.Id_pin3);
        materialAnimatedSwitch4 = (MaterialAnimatedSwitch) findComponentById(ResourceTable.Id_pin4);
        masterSwitch = (MaterialAnimatedSwitch) findComponentById(ResourceTable.Id_masterSwitch);

        toastDialog = new ToastDialog(getContext());
        toastDialog.setOffset(0, 200);

        materialAnimatedSwitch.setOnCheckedChangeListener(
                new MaterialAnimatedSwitch.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(boolean isChecked) {

                        toastDialog.setText(materialAnimatedSwitch.isChecked() + "").show();
                        materialAnimatedSwitch2.toggle();
                    }
                });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
